package day1202zuoye;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;

public class demo2 {
    public static void main(String[] args) {
        ArrayList<Dog> list = new ArrayList<>();
            list.add(new Dog("哈士奇",1,3));
            list.add(new Dog("藏獒",2,12));
            list.add(new Dog("博美",2,6));
            list.add(new Dog("柴犬",3,12));
            Collections.sort(list, new Comparator<Dog>() {
            @Override
            public int compare(Dog o1, Dog o2) {
                if (o2.getAge()-o1.getAge()<0){
                    return -1;
                }
                if (o2.getAge()-o1.getAge()==0){
                    return o2.getWeight()-o1.getWeight();
                }
                else return 0;
            }
        });
        System.out.println(list);
    }
}
